/***************************************************************************
 *   Copyright (C) 2008 by JBox systems
 *   gabi@shaargiora.co.il
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 ***************************************************************************/

#pragma once

#include <boost/filesystem.hpp>
#include <string>
#include <exception>

#include "version.h"

/**
	Utility class that installs applications.
*/
class Installer {

	private:

		/**
			Set to true when installer is perfoming installation.
		*/
		bool busy;

		/**
			Exit code of last operation.
		*/
		int lastcode;

		/**
			Name of last installed Application.
		*/
		std::string lastApp;

		/**
			Internal installation function.

			@param app Version to install.
			@param dryrun Won't execute the installer if true.
		*/
		void runInstaller(Version app, bool dryrun);

	public:

		Installer();
		virtual ~Installer();

		/**
			Installs the given version.

			@param app Version to install.
			@param dryrun Passed to runInstaller.
		*/
		void install(Version app, bool dryrun=false);

		/**
			Returns exit code of last installation.

			@return Exit code.
		*/
		int lastCode() { return lastcode; }

		/**
			Exception. Installer is busy.
		*/
		class Busy : public std::exception {};
};
